import { DD_SYSTEM } from '@/constants/api-pre';
import { request } from '@/service/request';

export type SmsTemplate = Api.Common.CommonRecord<{
  type: number;

  code: string;

  name: string;

  content: string;

  params: string[];

  remark: string;

  apiTemplateId: string;

  channelId: number;

  channelCode: string;

  createTime: string;
}>;

export type SmsTemplateEditAndCreateParams = CommonType.RecordNullable<
  Pick<
    SmsTemplate,
    'type' | 'code' | 'status' | 'name' | 'content' | 'remark' | 'apiTemplateId' | 'channelId' | 'channelCode'
  >
>;

export type SmsTemplateList = Api.Common.PaginatingQueryRecord<SmsTemplate>;

export type SmsTemplateSearchParams = CommonType.RecordNullable<
  Pick<SmsTemplate, 'type' | 'status' | 'code' | 'apiTemplateId' | 'channelId' | 'createTime'> &
    Api.Common.CommonSearchParams
>;

export interface TemplateParam {
  code: string;
  value: string;
}

export interface SendSmsReqVO {
  mobile: string;
  templateCode: string;
  templateParams: Map<string, string>;
  content: string;
  params: string[];
}

export function getFetchSmsTemplateUrl(id: number) {
  return `${DD_SYSTEM}/sms-template/${id}/form`;
}

export function fetchSmsTemplateList(params?: SmsTemplateSearchParams) {
  return request<SmsTemplateList>({
    url: `${DD_SYSTEM}/sms-template/page`,
    method: 'get',
    params
  });
}
export function createSmsTemplate(data: any) {
  return request<boolean>({
    url: `${DD_SYSTEM}/sms-template`,
    method: 'post',
    data
  });
}
export function updateSmsTemplate(id: number, data?: any) {
  return request<boolean>({
    url: `${DD_SYSTEM}/sms-template/${id}`,
    method: 'put',
    data
  });
}
export function deleteSmsTemplate(id: string) {
  return request<boolean>({
    url: `${DD_SYSTEM}/sms-template/${id}`,
    method: 'delete'
  });
}
export function sendSms(data: SendSmsReqVO) {
  return request<number>({
    url: `${DD_SYSTEM}/sms-template/send-sms`,
    method: 'post',
    data
  });
}
